<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="150px">
            <el-form-item :label="$t('vehicle.brand.vehicleBrand')" prop="brandId">
                <el-select v-model="queryParams.brandId" :placeholder="$t('vehicle.brand.placeholder.vehicleBrand')">
                    <el-option v-for="dict in brandList" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item :label="$t('vehicle.series.modelName')" prop="seriesId">
                <el-select v-model="queryParams.seriesId" :placeholder="$t('vehicle.series.placeholder.modelName')">
                    <el-option v-for="dict in seriesList" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item :label="$t('vehicle.type.vehicleModel')" prop="id">
                <el-select v-model="queryParams.id" :placeholder="$t('vehicle.type.placeholder.vehicleModel')">
                    <el-option v-for="dict in typesList" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{
                    $t('common.button.query') }}</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('common.button.reset')
                }}</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['vehicle:type:add']">{{ $t('common.button.add') }}</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['vehicle:type:edit']">{{ $t('common.button.edit') }}</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                    v-hasPermi="['vehicle:type:remove']">{{ $t('common.button.remove') }}</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['vehicle:type:export']">{{ $t('common.button.export') }}</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="ID" align="center" prop="id" />
            <el-table-column :label="$t('vehicle.type.vehicleModel')" align="center" prop="typeName" />
            <el-table-column :label="$t('vehicle.brand.vehicleBrand')" align="center" prop="brandName" />
            <el-table-column :label="$t('vehicle.series.modelName')" align="center" prop="vehicleSeries" />
            <el-table-column :label="$t('vehicle.type.batteryType')" align="center" width="230">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.battery_type" :value="scope.row.batteryType" />
              </template>
            </el-table-column>
            <el-table-column :label="$t('vehicle.type.vehicleParts')" align="center" prop="numberParts">
                <template slot-scope="scope">
                    <el-button class="custom-button" text="text" @click="getVehicleParts(scope.row)">
                        {{ scope.row.numberParts }}
                    </el-button>
                </template>
            </el-table-column>

            <el-table-column :label="$t('common.table.createBy')" align="center" width="130" prop="createBy" />
            <el-table-column prop="createTime" align="center" :label="$t('common.table.createTime')" width="170">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column :label="$t('common.table.operate')" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['vehicle:type:edit']">{{ $t('common.button.edit') }}</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['vehicle:type:remove']">{{ $t('common.button.remove') }}</el-button>
                    <el-button size="mini" type="text" icon="el-icon-setting" @click="handleSettings(scope.row)"
                        v-hasPermi="['vehicle:type:settings']">{{ $t('vehicle.type.settings') }}</el-button>
                    <el-button size="mini" type="text" icon="el-icon-setting" @click="handleVehicleSettings(scope.row)"
                        v-hasPermi="['vehicle:type:settings']">{{ $t('vehicle.type.control') }}</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

        <!-- 添加车辆车型对话框 -->
        <el-dialog :title="title" :visible.sync="addOpen" width="700px" append-to-body @close="dialogClose">
            <el-form ref="dataForm" :model="dataForm" :rules="dataRules" label-width="120px">
                <el-form-item :label="$t('vehicle.brand.vehicleBrand')" prop="brandId">
                    <el-select v-model="dataForm.brandId" :placeholder="$t('vehicle.brand.rules.brand')" clearable size="small" style="width:200px" @change="handleChange">
                        <el-option v-for="dict in brandList" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('vehicle.series.modelName')" prop="seriesId">
                    <el-select v-model="dataForm.seriesId" :placeholder="$t('vehicle.brand.rules.series')" clearable size="small" style="width:200px">
                        <template v-if="seriesList.length">
                            <el-option v-for="dict in seriesList" :key="dict.value" :label="dict.label" :value="dict.value" />
                        </template>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('vehicle.type.batteryType')" prop="batteryType">
                    <el-select v-model="dataForm.batteryType" clearable :placeholder="$t('vehicle.type.placeholder.batterType')"
                        style="width:200px">
                        <el-option v-for="dict in dict.type.battery_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <div v-for="(item, index) in  dataForm.typeNameList " :key="index" style="display: flex; align-items: center;">
                    <el-form-item 
                        :label="$t('vehicle.type.vehicleModel')" 
                        :prop="`typeNameList.${index}.typeName`"
                        :rules="dataRules.typeNameList" style="flex: 1;">
                        
                        <el-input v-model="item.typeName" :placeholder="$t('vehicle.type.placeholder.vehicleModel')"
                            style="width:200px" />
                    </el-form-item>
                    <el-form-item>
                        <el-button v-if="index + 1 == dataForm.typeNameList.length" @click="addInput" type="primary">{{
                            $t('common.button.add') }}</el-button>
                        <el-button v-if="index !== 0" @click="deleteInput(item, index)" type="danger">{{
                            $t('common.button.remove') }}</el-button>
                    </el-form-item>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :loading="buttonLoading" type="primary" @click="submitForm">{{
                    $t('common.dialog.confirm') }}</el-button>
                <el-button @click="cancel">{{ $t('common.dialog.cancel') }}</el-button>
            </div>
        </el-dialog>


        <!-- 修改车辆车型对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body @close="dialogClose">
            <el-form ref="dataForm" :model="dataForm" :rules="dataRules" label-width="120px">
                <el-form-item :label="$t('vehicle.brand.vehicleBrand')" prop="brandId">
                    <el-select v-model="dataForm.brandId" :placeholder="$t('vehicle.brand.rules.brand')" disabled size="small" style="width:200px">
                        <el-option v-for="dict in brandList" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('vehicle.series.modelName')" prop="seriesId">
                    <el-select v-model="dataForm.seriesId" :placeholder="$t('vehicle.brand.rules.series')" disabled size="small" style="width:200px">
                        <el-option v-for="dict in seriesList" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('vehicle.type.batteryType')" prop="batteryType">
                    <el-select v-model="dataForm.batteryType" clearable :placeholder="$t('vehicle.type.placeholder.batterType')"
                        style="width:200px">
                        <el-option v-for="dict in dict.type.battery_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('vehicle.type.vehicleModel')" prop="typeName">
                    <el-input v-model="dataForm.typeName" :placeholder="$t('vehicle.type.placeholder.vehicleModel')"
                        style="width:200px" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :loading="buttonLoading" type="primary" @click="submitForm">{{
                    $t('common.dialog.confirm') }}</el-button>
                <el-button @click="cancel">{{ $t('common.dialog.cancel') }}</el-button>
            </div>
        </el-dialog>


        <!-- 车辆零部件弹窗 -->
        <el-dialog :title="attachmentTitle" :visible.sync="attachmentOpen" width="1000px" append-to-body>
            <el-table v-loading="attachmenLoading" border :data="attachmentList">
                <el-table-column label="ID" align="center" prop="id" />
                <el-table-column :label="$t('vehicle.attachment.partType')" align="center" prop="attachmentTypeName" />
                <el-table-column :label="$t('vehicle.attachment.partName')" align="center" prop="attachmentName" />
            </el-table>
        </el-dialog>
         <!-- 参数设置弹窗 -->
         <el-dialog title="参数设置" :visible.sync="paramsOpen" width="800px" append-to-body>
            <el-row v-if="language === 'zh_CN'">
                <el-checkbox-group v-model="paramsSettingList"  @change="handleCheckedParams">
                    <el-col :span="8" v-for="item in paramsList" >
                        <el-checkbox  :label="item" :key="item.paramValue" @change="handleClick(item)">{{item.paramLabel}}</el-checkbox>
                    </el-col>  
                </el-checkbox-group>
            </el-row>
            <el-row v-else-if="language === 'en_US'">
                <el-checkbox-group v-model="paramsSettingList"  @change="handleCheckedParams">
                    <el-col :span="8" v-for="item in paramsList" >
                        <el-checkbox  :label="item" :key="item.paramValue" @change="handleClick(item)">{{item.paramLabel}}</el-checkbox>
                    </el-col>  
                </el-checkbox-group>
            </el-row>
            <el-col :span="8" :offset="16">
                    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">{{ $t('common.button.all')}}</el-checkbox>
                </el-col>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel">{{ $t('common.dialog.cancel') }}</el-button>
                <el-button :loading="buttonLoading" type="primary" @click="saveParams">{{
                    $t('common.button.save') }}</el-button>
            </div>
        </el-dialog>
        <!-- 车辆控制弹窗 -->
        <el-dialog title="车辆控制" :visible.sync="vehicleOpen" width="800px" append-to-body>
            <el-loading  :text="loadingText" :fullscreen="false" :visible="loadingDialog">
              <div style="padding: 20px; height: 100px;">
                <el-row v-if="language === 'zh_CN'">
                    <el-checkbox-group v-model="vehicleControlList"  @change="handleCheckedControl">
                        <el-col :span="8" v-for="item in controlList" >
                            <el-checkbox  :label="item" :key="item.paramValue" @change="handleClick(item)">{{item.paramLabel}}</el-checkbox>
                        </el-col>  
                    </el-checkbox-group>
                </el-row>
                <el-row v-else-if="language === 'en_US'">
                    <el-checkbox-group v-model="vehicleControlList"  @change="handleCheckedControl">
                        <el-col :span="8" v-for="item in controlList" >
                            <el-checkbox  :label="item" :key="item.paramValue" @change="handleClick(item)">{{item.paramLabel}}</el-checkbox>
                        </el-col>  
                    </el-checkbox-group>
                </el-row>
              </div>
            </el-loading>  
            
            <el-col :span="8" :offset="16">
                    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">{{ $t('common.button.all')}}</el-checkbox>
            </el-col>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel">{{ $t('common.dialog.cancel') }}</el-button>
                <el-button :loading="buttonLoading" type="primary" @click="saveControl">{{
                    $t('common.button.save') }}</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { listBrand } from "@/api/vehicle/brand/data";
import { listSeries,getSeriesByBrandId } from "@/api/vehicle/series/data";
import { listAttachment } from "@/api/vehicle/attachment/data";
import { listType, getType, delType, addType, updateType,addParams,queryTypeParams,editParams,addControl,queryTypeControl,editControl } from "@/api/vehicle/type/data";
import { listCommandParams } from "@/api/parameter/item/data";
import { getLanguage } from "@/utils/auth";
export default {
    name: "Type",
    dicts: ['battery_type'],
    data() {
        return {
            isIndeterminate: false,
            checkAll: false,
            addOpen: false,
            inputList: [{ typeName: '' }],
            attachmenLoading: false,
            attachmentList: [],
            attachmentOpen: false,
            attachmentTitle: '',
            vehicleTypeId:"",
            all:false,
            typesList: [],
            seriesList: [],
            brandList: [],
            paramsList:[],
            paramsSettingList:[],
            // 按钮loading
            buttonLoading: false,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 车辆车型表格数据
            typeList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                typeName: undefined,
                brandId: undefined,
                seriesId: undefined,
            },
            // 表单参数
            form: {},
            dataForm:{
                brandId:undefined,
                seriesId:undefined,
                batteryType:undefined,
                typeNameList:[{typeName:""}]
            },
            paramsQuery:{
                commandType:4,//车辆查询
            },
            paramsOpen:false,//参数设置弹窗
            vehicleQuery:{
                commandType:5,//车辆控制

            },
            controlList:[],
            vehicleControlList:[],
            vehicleOpen:false,//车辆控制弹窗
            // 表单校验
            dataRules:{
                brandId: [
                    { required: true, message: this.$t('vehicle.brand.rules.brand'), trigger: ["blur","change"] }
                ],
                seriesId: [
                    { required: true, message: this.$t('vehicle.series.rules.model'), trigger: ["blur","change"] }
                ],
                batteryType:[
                    { required: true, message: this.$t('vehicle.type.rules.batteryType'), trigger: "change" }

                ],
                typeNameList: [
                    {
                        required: true,
                        message: this.$t('vehicle.type.rules.type'),
                        trigger: "blur"
                    }
                ],
            },
            rules: {
                // typeName: [
                //     { required: true, message: "车型型号名称不能为空", trigger: "blur" }
                // ],
                brandId: [
                    { required: true, message: this.$t('vehicle.brand.rules.brand'), trigger: "blur" }
                ],
                seriesId: [
                    { required: true, message: this.$t('vehicle.series.rules.model'), trigger: "blur" }
                ],
            },
            //参数设置表单
            paramsForm:{
                vehicleTypeId:"",
                //刹车断电
                brakePowerOutage:0,
                //边撑开关
                sideSupportSwitch:0,
                //ABS开关
                absSwitch:0,
                //坡道辅助开关
                hillAssistSwitch:0,
                //坡道缓坡开关
                rampSwitch:0,
                //开电池阀
                openBatteryValve:0,
                //开机默认驾驶模式
                defaultDrivingMode:0,
                //运动档动力曲线
                sportPowerCurve:0,
                //舒适档动力曲线
                comfortPowerCurve:0,
                //防盗器音源选择
                antiTheftSoundSource:0,
                //防盗器按键声音大小
                antiTheftButtonSoundLevel:0,
                //防盗器转向声音大小
                antiTheftTurnSoundLevel:0,
                //TCS强度
                tcsStrength:0,
                //蓝牙强度
                bluetoothStrength:0,
                //原地设防
                setDefenses:0,
                //车辆丢失设置
                vehicleLossSettings:0,
                //公英制切换
                metricAndImperial:0,
                //充电功率
                vehicleChargingPower:0,       
                //刹车能量回收等级
                brakeEnergyRecoveryLevel:0,
                //滑行能量回收等级
                coastingEnergyRecoveryLevel:0,
                //防盗声音大小
                antiTheftSound:0,
                //SPORT 档动力曲线
                powerCurveSport:0,
                //0 车速起步时间
                zeroSpeedStartTime:0,
                //0 车速斜率设置
                zeroSpeedSlopeSetting:0,
                //SPORT 档最高车速设置
                maximumSpeedSettingSport:0,
                //NORMAL 档最高车速设置
                normalMaximumSpeedSetting:0,
                //小里程清零
                smallMileageClearZero:0,
                //自动进P时间设置
                setPtimeAutomatically:0
            },
            //车辆控制表单
            controlForm:{
                vehicleTypeId:"",
                //坐垫
                cushion:0,
                //尾箱
                trunk:0,
                //寻车
                carFinding:0,
                //电磁阀
                solenoidValve:0,
                //电门锁控制
                electricDoorLockControl:0,
                //设撒放
                setOff:0,
                //总里程清零
                totalMileageClearedToZero:0
            },
            isSet:false
            
        };
    },
    computed: {
        language() {
            return getLanguage()
        }   
    },
    created() {
        this.getList();
        this.getBrandList();
        this.getSeriesList();
        this.getTypeList();
        this.getParamsList();
        this.getControlList();
    },
    methods: {
        /** 查询车辆车型列表 */
        getList() {
            this.loading = true;
            listType(this.queryParams).then(response => {
                this.typeList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.addOpen = false;
            this.open = false;
            this.paramsOpen = false;
            this.vehicleOpen = false;
            this.reset();
        },
        // 表单重置
        reset() {
            // this.dataForm.typeNameList = [{ typeName: "" }],
                this.dataForm = {
                    id: undefined,
                    typeName: undefined,
                    brandId: undefined,
                    seriesId: undefined,
                    createBy: undefined,
                    updateBy: undefined,
                    createTime: undefined,
                    updateTime: undefined,
                    typeNameList : [{ typeName: "" }]
                };

            this.resetForm("dataForm");
            
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        addInput() {
            this.dataForm.typeNameList.push({ typeName: '' });
            // this.$nextTick(() => {
            //     this.$refs.form.validate();
            // });
        },
        deleteInput(item, index) {
            if ( this.dataForm.typeNameList.length > 1) {
                this.dataForm.typeNameList.splice(index, 1);
                // this.$nextTick(() => {
                //     this.$refs.form.validate();
                // });
            }
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.addOpen = true;
            this.title = this.$t('vehicle.type.title.add');
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.loading = true;
            this.reset();
            const id = row.id || this.ids;
            getType(id).then(response => {
                this.loading = false;
                this.dataForm = response.data;
                this.dataForm.typeNameList = [{typeName:""}]
                this.open = true;
                this.title = this.$t('vehicle.type.title.edit');
            });
        },
        //级联选择
        handleChange(e){
            const brandId = e;
            if (brandId == null || brandId == "") {
               this.seriesList = [];
               this.dataForm.seriesId = "";
               return;
            }
            getSeriesByBrandId(e).then(res =>{
                this.seriesList =  res.data.map(item =>{
                        return {
                            label:item.vehicleSeries,
                            value:item.id
                        }
                    })                
                })  
            console.log("品牌ID"+e);
           
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["dataForm"].validate(valid => {
                if (valid) {
                    this.buttonLoading = true;
                    if (this.dataForm.id != null) {
                        updateType(this.dataForm).then(response => {
                            this.$modal.updateSuccess();
                            this.open = false;
                            this.reset();
                            this.getList();
                        }).finally(() => {
                            this.buttonLoading = false;
                        });
                    } else {
                        addType(this.dataForm).then(response => {
                            this.$modal.addSuccess();
                            this.addOpen = false;
                            this.getList();
                        }).finally(() => {
                            this.buttonLoading = false;
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm(this.$t('vehicle.type.title.delete') + ids + this.$t('vehicle.type.title.query')).then(() => {
                this.loading = true;
                return delType(ids);
            }).then(() => {
                this.loading = false;
                this.getList();
                this.$modal.deleteSuccess();
            }).catch(() => {
            }).finally(() => {
                this.loading = false;
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('vehicle/type/export', {
                ...this.queryParams
            }, `type_${new Date().getTime()}.xlsx`)
        },
        /* 参数设置操作 */
        handleSettings(row){
            this.vehicleTypeId = row.id;
            this.paramsForm.vehicleTypeId = this.vehicleTypeId;
            queryTypeParams(row.id).then(res =>{
                console.log(res.data);
                if (res.data != null) {
                    this.paramsEcho(res.data)
                    this.isSet =true;
                }else{
                    this.isSet = false;
                    this.paramsOpen = true;
                    this.paramsSettingList = [];
                }
            })
        },
         /* 车辆控制操作 */
         handleVehicleSettings(row){
            this.vehicleTypeId = row.id;
            this.controlForm.vehicleTypeId = this.vehicleTypeId;
            this.loading = true;
            queryTypeControl(row.id).then(res =>{
                console.log(res.data);
                if (res.data != null) {
                    this.controlEcho(res.data)
                    this.isSet =true;
                    this.loading =false;
                }else{
                    this.isSet = false;
                    this.vehicleOpen = true;
                    this.vehicleControlList = [];
                }
            })
     
        },

        /* 参数提交 */
        saveParams(){
            console.log(this.paramsSettingList);
            this.paramsSettings(this.paramsSettingList);
        },
        /* 控制提交 */
        saveControl(){
            console.log(this.vehicleControlList);
            this.controlSettings(this.vehicleControlList);
        },
        getBrandList() {
            listBrand().then(response => {
                this.brandList = response.rows.map(item => {
                    return {
                        label: item.vehicleBrand,
                        value: item.id
                    }
                })
            })
        },
        getSeriesList() {
            listSeries().then(response => {
                this.seriesList = response.rows.map(item => {
                    return {
                        label: item.vehicleSeries,
                        value: item.id
                    }
                })
            })
        },

        getTypeList() {
            listType().then(response => {
                this.typesList = response.rows.map(item => {
                    return {
                        label: item.typeName,
                        value: item.id,
                        show:1
                    }
                })
            })
        },

        getVehicleParts(row) {
            console.log(row);
            this.attachmentTitle = this.$t('vehicle.attachment.associatedParts');
            this.attachmentOpen = true;
            this.attachmenLoading = true;
            var data = {};
            data.typeId = row.id;
            listAttachment(data).then(response => {
                this.attachmentList = response.rows;
                this.attachmenLoading = false;
            })
        },
        //获取参数列表
        getParamsList(){
            listCommandParams(this.paramsQuery).then(res =>{
                this.paramsList = res.rows.map(item =>{
                    item.show = false;
                    return{
                        paramLabel:this.language==="zh_CN" ? item.paramLabelZhCn:item.paramLabelEnUs,
                        paramValue:item.paramValue
                    }
                })
                console.log(res);
            })
        },
        //获取车辆控制列表
        getControlList(){
            listCommandParams(this.vehicleQuery).then(res =>{
                this.controlList = res.rows.map(item =>{
                    item.show = false;
                    return{
                        paramLabel:this.language==="zh_CN" ? item.paramLabelZhCn:item.paramLabelEnUs,
                        paramValue:item.paramValue
                    }
                })
                console.log(res);
            })
        },
        //参数设置复选框点击事件
        handleCheckedParams(value){
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.paramsList.length;
            this.isIndeterminate = checkedCount > 0 && checkedCount < this.paramsList.length;
        },
        //车辆控制复选框点击事件
        handleCheckedControl(value){
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.controlList.length;
            this.isIndeterminate = checkedCount > 0 && checkedCount < this.controlList.length;
        },
        handleClick(value){
            console.log(value);
         },
        handleCheckAllChange(val) {
            this.paramsSettingList = val ? this.paramsList : [];
            this.vehicleControlList = val ? this.controlList : [];
            this.isIndeterminate = false;
        },
        handleAll(){
            console.log(this.all);

            // if (this.all) {
            //     this.paramsList = this.paramsList.map(item=>{
            //         return{
            //             label:item.label,
            //             value:item.value,
            //             show:true
            //         }
            //     }
            //     )
            //     this.paramsSettingList= this.paramsList.map(item =>{
            //         return item.value+"";

            //     }
            //     )
            //     console.log(this.paramsList);
            //     console.log(this.paramsSettingList);
            // }
        },
        //对话框关闭回调
        dialogClose(){
            console.log("对话框关闭");
            // this.resetForm("dataForm");
            this.$refs['dataForm'].resetFields();
            this.dataForm.typeNameList = [{ typeName: '' }];

        },
        // 参数属性设置
        paramsSettings(list){ 
            this.paramsReset();
            this.paramsForm.vehicleTypeId = this.vehicleTypeId;
            for (let i = 0; i < list.length; i++) {
               switch (list[i].paramValue) {
                    case 101:
                             this.paramsForm.brakePowerOutage = 1;
                        break;
                    case 102:
                             this.paramsForm.sideSupportSwitch = 1;
                        break;
                    case 103:
                             this.paramsForm.absSwitch = 1;
                        break;
                    case 104:
                             this.paramsForm.hillAssistSwitch = 1;
                        break;
                    case 105:
                             this.paramsForm.rampSwitch = 1;
                        break;
                    case 106:
                             this.paramsForm.openBatteryValve = 1;
                        break;
                    case 107:
                             this.paramsForm.defaultDrivingMode = 1;
                        break;
                    case 108:
                             this.paramsForm.sportPowerCurve = 1;
                        break;
                    case 109:
                             this.paramsForm.comfortPowerCurve = 1;
                        break;
                    case 110:
                             this.paramsForm.antiTheftSoundSource = 1;
                        break;
                    case 111:
                             this.paramsForm.antiTheftButtonSoundLevel = 1;
                        break;
                    case 112:
                             this.paramsForm.antiTheftTurnSoundLevel = 1;
                        break;
                    case 113:
                             this.paramsForm.tcsStrength = 1;
                        break;
                    case 114:
                             this.paramsForm.bluetoothStrength = 1;
                        break;
                    case 115:
                             this.paramsForm.vehicleLossSettings = 1;
                        break;
                    case 116:
                             this.paramsForm.metricAndImperial = 1;
                        break;
                    case 117:
                             this.paramsForm.setDefenses = 1;
                        break;
                    case 118:
                            this.paramsForm.vehicleChargingPower = 1;
                    break;
                    case 119:
                            this.paramsForm.brakeEnergyRecoveryLevel = 1;
                    break;
                    case 120:
                            this.paramsForm.coastingEnergyRecoveryLevel = 1;
                    break;
                    case 121:
                            this.paramsForm.antiTheftSound = 1;
                    break;
                    case 122:
                            this.paramsForm.powerCurveSport = 1;
                    break;
                    case 123:
                            this.paramsForm.zeroSpeedStartTime = 1;
                    break;
                    case 124:
                            this.paramsForm.zeroSpeedSlopeSetting = 1;
                    break;
                    case 125:
                            this.paramsForm.maximumSpeedSettingSport = 1;
                    break;
                    case 126:
                            this.paramsForm.normalMaximumSpeedSetting = 1;
                    break;
                    case 127:
                            this.paramsForm.smallMileageClearZero = 1;
                    break;
                    case 128:
                            this.paramsForm.setPtimeAutomatically = 1;
                    break;
                   
                } 
            }
            console.log(this.paramsForm);
            if (this.isSet) {
                editParams(this.paramsForm).then(res =>{
                if (res.code == 200) {
                    this.$message.success(this.$t("common.operate.tip.executionSuccess"))
                    this.paramsOpen = false;
                    this.paramsSettingList = [];
                    this.checkAll = false;
                    this.isIndeterminate = false;
                }
            })
            }else{
                addParams(this.paramsForm).then(res =>{
                if (res.code == 200) {
                    this.$message.success(this.$t("common.operate.tip.executionSuccess"))
                    this.paramsOpen = false;
                    this.paramsSettingList = [];
                    this.checkAll = false;
                    this.isIndeterminate = false;
                }
            })
            }
            
        },
        //参数回显设置
        paramsEcho(data){
            this.paramsSettingList = [];
            console.log("===============>",data);
            for (let i = 0; i < this.paramsList.length; i++) {
                    if (this.paramsList[i].paramValue == 101 && data.brakePowerOutage == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 102 && data.sideSupportSwitch == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 103 && data.absSwitch == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 104 && data.hillAssistSwitch == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 105 && data.rampSwitch == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 106 && data.openBatteryValve == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 107 && data.defaultDrivingMode == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 108 && data.sportPowerCurve == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 109 && data.comfortPowerCurve == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 110 && data.antiTheftSoundSource == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 111 && data.antiTheftButtonSoundLevel == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 112 && data.antiTheftTurnSoundLevel == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 113 && data.tcsStrength == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 114 && data.bluetoothStrength == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 115 && data.vehicleLossSettings == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 116 && data.metricAndImperial == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 117 && data.setDefenses == 1) {
                        this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 118 && data.vehicleChargingPower == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 119 && data.brakeEnergyRecoveryLevel == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 120 && data.coastingEnergyRecoveryLevel == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                    } 
                else if (this.paramsList[i].paramValue == 121 && data.antiTheftSound == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                    }
                else if (this.paramsList[i].paramValue == 122 && data.powerCurveSport == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                } else if (this.paramsList[i].paramValue == 123 && data.zeroSpeedStartTime == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                } else if (this.paramsList[i].paramValue == 124 && data.zeroSpeedSlopeSetting == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                } else if (this.paramsList[i].paramValue == 125 && data.maximumSpeedSettingSport == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                } else if (this.paramsList[i].paramValue == 126 && data.normalMaximumSpeedSetting == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                } else if (this.paramsList[i].paramValue == 127 && data.smallMileageClearZero == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                } else if (this.paramsList[i].paramValue == 128 && data.setPtimeAutomatically == 1) {
                    this.paramsSettingList.push(this.paramsList[i])
                }  
            }
            console.log("=======>",this.paramsSettingList);
            this.paramsOpen = true;
        },
        // 参数重置
        paramsReset(){
            this.paramsForm = {
                vehicleTypeId:"",
                brakePowerOutage:0,
                sideSupportSwitch:0,
                absSwitch:0,
                hillAssistSwitch:0,
                rampSwitch:0,
                openBatteryValve:0,
                defaultDrivingMode:0,
                sportPowerCurve:0,
                comfortPowerCurve:0,
                antiTheftSoundSource:0,
                antiTheftButtonSoundLevel:0,
                antiTheftTurnSoundLevel:0,
                tcsStrength:0,
                bluetoothStrength:0,
                setDefenses:0,
                vehicleLossSettings:0,
                metricAndImperial:0,
                brakeEnergyRecoveryLevel:0,
                coastingEnergyRecoveryLevel:0,
                antiTheftSound:0,
                powerCurveSport:0,
                zeroSpeedStartTime:0,
                zeroSpeedSlopeSetting:0,
                maximumSpeedSettingSport:0,
                normalMaximumSpeedSetting:0,
                smallMileageClearZero:0,
                setPtimeAutomatically:0
            }
        },
        // 车辆控制设置
        controlSettings(list){ 
            this.controlReset();
            this.controlForm.vehicleTypeId = this.vehicleTypeId;
            for (let i = 0; i < list.length; i++) {
               switch (list[i].paramValue) {
                    case 150:
                             this.controlForm.cushion = 1;
                        break;
                    case 151:
                             this.controlForm.trunk = 1;
                        break;
                    case 152:
                             this.controlForm.carFinding = 1;
                        break;
                    case 153:
                             this.controlForm.solenoidValve = 1;
                        break;
                    case 154:
                             this.controlForm.electricDoorLockControl = 1;
                        break;
                    case 155:
                             this.controlForm.setOff = 1;
                        break;
                    case 156:
                             this.controlForm.smallMileageClearedToZero = 1;
                        break;
                    
                } 
            }
           
            if (this.isSet) {
                editControl(this.controlForm).then(res =>{
                if (res.code == 200) {
                    this.$message.success(this.$t("common.operate.tip.executionSuccess"))
                    this.vehicleOpen = false;
                    this.vehicleControlList = [];
                    this.checkAll = false;
                    this.isIndeterminate = false;
                }
            })
            }else{
                addControl(this.controlForm).then(res =>{
                if (res.code == 200) {
                    this.$message.success(this.$t("common.operate.tip.executionSuccess"))
                    this.vehicleOpen = false;
                    this.vehicleControlList = [];
                    this.checkAll = false;
                    this.isIndeterminate = false;
                }
            })
            }
            
        },
        //车辆控制回显设置
        controlEcho(data){
            this.vehicleControlList = [];
            
            for (let i = 0; i < this.controlList.length; i++) {
                    if (this.controlList[i].paramValue == 150 && data.cushion == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
                else if (this.controlList[i].paramValue == 151 && data.trunk == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
                else if (this.controlList[i].paramValue == 152 && data.carFinding == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
                else if (this.controlList[i].paramValue == 153 && data.solenoidValve == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
                else if (this.controlList[i].paramValue == 154 && data.electricDoorLockControl == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
                else if (this.controlList[i].paramValue == 155 && data.setOff == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
                else if (this.controlList[i].paramValue == 156 && data.smallMileageClearedToZero == 1) {
                        this.vehicleControlList.push(this.controlList[i])
                    } 
              
            }
            console.log("=======>",this.paramsSettingList);
            this.vehicleOpen = true;
        },
        // 车辆控制重置
        controlReset(){
            this.controlForm = {
                vehicleTypeId:"",
                cushion:0,
                trunk:0,
                carFinding:0,
                solenoidValve:0,
                electricDoorLockControl:0,
                setOff:0,
                smallMileageClearedToZero:0
            }
        },
       
    }
};
</script>
<style >
.custom-button {
    border-color: transparent;
    color: blue;
}
</style>
